package com.cgsrp.cgsrp_shopping.controller;

import com.cgsrp.cgsrp_shopping.domain.ShoppingCart;
import com.cgsrp.cgsrp_shopping.service.ShoppingCartService;
import com.cgsrp.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("cart")
public class CartController {
    @Autowired
    private ShoppingCartService shoppingCartService;

    @PostMapping("add")
    public Result add(Integer userId,Integer productId,Integer number){
        return shoppingCartService.add(userId,productId,number);
    }

    @GetMapping("list")
    public Result list(
            @RequestParam(defaultValue = "1")Integer curPage,
            @RequestParam(defaultValue = "24")Integer pageSize,
            Integer userId
    ){
        return shoppingCartService.list(curPage,pageSize,userId);
    }

    @PostMapping("del")
    public Result del(Integer productId){
        return shoppingCartService.deleteByPrimaryKey(productId)>0?Result.success("删除成功"):Result.failure("删除失败");
    }
}
